﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ICU.Utils
{
    class NullableDictionary<TKey, TValue>
    {
        private Dictionary<TKey, TValue> data;
        public TValue @default;

        public NullableDictionary(TValue @default)
        {
            this.@default = @default;
            data = new Dictionary<TKey, TValue>();
        }

        public TValue this[TKey key] { get { return data.ContainsKey(key) ? data[key] : @default; }
            set { if (data.ContainsKey(key)) data[key] = value; else data.Add(key, value); } }
        public void Clear()
        {
            data.Clear();
        }
        public bool ContainsKey(TKey key)
        {
            return data.ContainsKey(key);
        }
    }
}
